/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.qb9.flashlib.logs
{
	import com.qb9.flashlib.color.Color;
	import com.qb9.flashlib.input.Console;
	import com.qb9.flashlib.interfaces.IDisposable;
	
	/**
	 * Sends the logs a flashlib's console
	 * @see com.qb9.flashlib.input.Console
	 */
	
	public class FlashlibConsoleAppender implements IAppender, IDisposable
	{
		private var console:Console;
		
		public function FlashlibConsoleAppender(console:Console)
		{
			this.console = console;
		}

		/** @inheritDoc */
		public function append(msg:Array,level:int):void
		{
			console.print(msg.join(' '), getColor(level));
		}
		
		private function getColor(num:int) : uint
		{
			switch(num)
			{
				default						 :
				case Logger.LOG_LEVEL_NONE   :
				case Logger.LOG_LEVEL_DEBUG  : return 0x999999;
				case Logger.LOG_LEVEL_INFO   : return 0x4BC3CB;
				case Logger.LOG_LEVEL_WARNING: return Color.YELLOW;
				case Logger.LOG_LEVEL_ERROR	 : return Color.RED;				
			}
		}
		
		public function dispose():void
		{
			console = null;
		}
	}
}
